package com.yzh.luckydraw.domain.rule.service.engine.impl;

import com.yzh.luckydraw.domain.rule.model.aggregates.TreeRuleRich;
import com.yzh.luckydraw.domain.rule.model.req.DecisionMatterReq;
import com.yzh.luckydraw.domain.rule.model.res.EngineResult;
import com.yzh.luckydraw.domain.rule.model.vo.TreeNodeVO;
import com.yzh.luckydraw.domain.rule.repository.IRuleRepository;
import com.yzh.luckydraw.domain.rule.service.engine.EngineBase;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class RuleEngineHandle extends EngineBase {
    @Resource
    private IRuleRepository ruleRepository;
    @Override
    public EngineResult process(DecisionMatterReq req) {
        //决策规则树
        TreeRuleRich treeRuleRich = ruleRepository.queryTreeRuleRich(req.getTreeId());
        if (treeRuleRich == null) {
            throw new RuntimeException("规则树为空");
        }
        //决策节点
        TreeNodeVO treeNodeVO = engineDecisionMaker(treeRuleRich, req);
        return new EngineResult(req.getUserId(), req.getTreeId(), treeNodeVO.getTreeNodeId(), treeNodeVO.getNodeValue());
    }
}
